package user.zc.controller.impl;

import user.zc.config.value.Key;
import user.zc.controller.ISystemTemplate;
import user.zc.service.SystemTemplateService;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class SystemTemplateController implements ISystemTemplate {

    private SystemTemplateService systemTemplateService = new SystemTemplateService();
    @Override
    public List<String> list() throws Exception {
        return systemTemplateService.templates();
    }

    @Override
    public void delete(String fileName) throws Exception {

    }

    @Override
    public void saveOrUpdate(String fileName,String content) throws Exception {
        systemTemplateService.saveOrUpdate(fileName, Arrays.stream(content.split("\n\r")).map(t->new Key(t)).collect(Collectors.toList()));
    }

    @Override
    public String read(String fileName) throws Exception {
        return systemTemplateService.read(fileName).stream().map(key -> key.getKey()).collect(Collectors.joining("\n\r"));
    }
}
